#pragma once

#include "CoreMinimal.h"
#include "SpatialCoordinate.generated.h"

USTRUCT(BlueprintType)
struct FSpatialCoordinate
{
	GENERATED_BODY()

	UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
	int32 X;

	UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
	int32 Y;

public:
	int32 ToId(const int32 Upper = 1024) const{
		return CoordinateToId(X, Y, Upper);
	}
	void FormId(int32 Id, const int32 Upper = 1024){
		IdToCoordinate(Id, X, Y, Upper);
	}
public:
	static int32 CoordinateToId(int32 X, int32 Y, const int32 Upper = 1024){
		return (X + Upper) + (Y + Upper) * Upper * 2;
	}
	static void IdToCoordinate(int32 Id, int32& X, int32& Y, const int32 Upper = 1024){
		X = Id % (Upper * 2) - Upper;
		Y = Id / (Upper * 2) - Upper;
	}
};